include("vgui/cl_teamSelect.lua")
include("vgui/cl_scoreboard.lua")
include("vgui/cl_voice.lua")
include("vgui/cl_hud.lua")
include("mapvote/cl_mapvote.lua")
include("vgui/cl_blockplacer.lua")

surface.CreateFont( "blockfont", { font = "TabLarge", size = 11, bold =true } )
surface.CreateFont( "MenuFont2", { font = "Coolvetica", size = 14 } )
surface.CreateFont( "MenuFont3", { font = "Coolvetica", size = 16.5 } )
surface.CreateFont( "MenuFont5", { font = "Coolvetica", size = 18 } )
surface.CreateFont( "MenuFont6", { font = "Coolvetica", size = 14 } )
surface.CreateFont( "MenuFont4", { font = "Coolvetica", size = 19 } )
surface.CreateFont( "HudFont4",  { font = "Coolvetica", size = 34 } )
surface.CreateFont( "TeamHeader",  { font = "Coolvetica", size = 54 } )

surface.CreateFont( "digital", {
font = "DS-Digital",
size = 41,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
additive = true,
outline = true,
})


TeamSelection_Open = false
blinded = false
Frame = nil
RoundStatusGUI = true
HidersWin = false
SeekersWin = false



usermessage.Hook("spawnsound", function()
	surface.PlaySound("items/medshot4.wav")
end)


usermessage.Hook("hiderswin", function()
	HidersWin = true
	timer.Simple( 4, function ()
		HidersWin = false 
	end)
end)


usermessage.Hook("seekerswin", function()
	SeekersWin = true
	timer.Simple( 4, function ()
		SeekersWin = false 
	end)
end)


Round_Phase = GetGlobalVar( "RoundPhase" )
hook.Add("HUDPaint", "RoundNotifacations", function()

	txtX = ScrW() / 2
	txtY = ScrH() / 2 * .7
	txtWhite = Color( 255, 255, 255, 255 )
	txtBlack = Color( 0, 0, 0, 155 )
	
	if HidersWin then
		draw.SimpleText( "Hiders won the Round!", "MenuFont5", txtX +1, txtY +1, txtBlack, TEXT_ALIGN_CENTER )
		draw.SimpleText( "Hiders won the Round!", "MenuFont5", txtX, txtY, txtWhite, TEXT_ALIGN_CENTER )
	elseif SeekersWin then
		draw.SimpleText( "Seekers won the Round!", "MenuFont5", txtX +1, txtY +1, txtBlack, TEXT_ALIGN_CENTER )
		draw.SimpleText( "Seekers won the Round!", "MenuFont5", txtX, txtY, txtWhite, TEXT_ALIGN_CENTER )	
	end

		--If in the ROUND_WAITING phase we will let the players know.
	if Round_Phase == 0 then
	draw.SimpleText( "Waiting for more players.", "MenuFont5", txtX+1, txtY+1, txtBlack, TEXT_ALIGN_CENTER )	
	draw.SimpleText( "Waiting for more players.", "MenuFont5", txtX, txtY, txtWhite, TEXT_ALIGN_CENTER )	
	else return 
	end
	 
end) 
  
  
 --Draws the glow around entities.
 --Thanks Garry!
 
local physgun_halo = CreateConVar( "physgun_halo", "1", { FCVAR_ARCHIVE }, "Draw the physics gun halo?" )
local PhysgunHalos = {}

function GM:DrawPhysgunBeam( ply, weapon, bOn, target, boneid, pos )
	if ( physgun_halo:GetInt() == 0 ) then return true end

	if ( IsValid( target ) ) then
		PhysgunHalos[ ply ] = target
	end
	return true
end

hook.Add( "PreDrawHalos", "AddPhysgunHalos", function()
	if ( !PhysgunHalos || table.Count( PhysgunHalos ) == 0 ) then return end

	for k, v in pairs( PhysgunHalos ) do

		if ( !IsValid( k ) ) then continue end

		local size = math.random( 1, 2 )
		local colr = k:GetWeaponColor() + VectorRand() * 0.3
		effects.halo.Add( PhysgunHalos, Color( colr.x * 255, colr.y * 255, colr.z * 255 ), size, size, 1, true, false )
	end

	PhysgunHalos = {}
end )


function hidehud(name)
	for k, v in pairs({"CHudHealth", "CHudBattery", "CHudCrosshair", "HUDDrawTargetID"})do
		if name == v then return false end
	end
end
hook.Add("HUDShouldDraw", "HideOurHud:D", hidehud)

function GM:HUDDrawTargetID()

	local tr = util.GetPlayerTrace( LocalPlayer() )
	local trace = util.TraceLine( tr )
	if (!trace.Hit) then return end
	if (!trace.HitNonWorld) then return end

	local text = "ERROR"
	local font = "TargetID"

	if (trace.Entity:IsPlayer()) then
		text = trace.Entity:Nick()
	else
		return
		--text = trace.Entity:GetClass()
	end

	surface.SetFont( font )
	local w, h = surface.GetTextSize( text )

	local MouseX, MouseY = gui.MousePos()

	if ( MouseX == 0 && MouseY == 0 ) then

		MouseX = ScrW() / 2
		MouseY = ScrH() / 2

	end

	local x = MouseX
	local y = MouseY

	x = x - w / 2
	y = y + 30

	-- The fonts internal drop shadow looks lousy with AA on
	draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,100) )
	draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,50) )
	draw.SimpleText( text, font, x, y, self:GetTeamColor( trace.Entity ) )

	y = y + h + 5

	local text = trace.Entity:Health() .. "%"
	local font = "TargetIDSmall"

	surface.SetFont( font )
	local w, h = surface.GetTextSize( text )
	local x =  MouseX  - w / 2

	draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,100) )
	draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,50) )
	draw.SimpleText( text, font, x, y, self:GetTeamColor( trace.Entity ) )
	

end

--Called when we want to hide huds
local tohide = {
	["CHudHealth"] = true,
	["CHudBattery"] = true,
	["CHudAmmo"] = true,
	["CHudSecondaryAmmo"] = true,
	["RoundStatusGUI"] = true
}

function HUDShouldDraw(name)
	if TeamSelection_Open or blinded or bOpen then
		if (tohide[name]) then
			return false;
		end
	else
		return true
	end
end
hook.Add("HUDShouldDraw", "Hides Shit", HUDShouldDraw)

